<template>
	<!-- 店员申请 -->
	<view class="clerkApplication">
		<view class="store_info_image">
			<image :src="imageUrls(store_info.image)" mode="widthFix" style="width: 100px; border-radius: 50%"></image>
		</view>
		<view class="store_info_name">门店名称：{{ store_info.name }}</view>
		<view class="bankCard-btn" :style="bottomStyle">
			<view class="btn" @click="getclerkApplication">点击申请</view>
		</view>
	</view>
</template>

<script>
import { userStaffApply } from '../../api/flashManage/index.js';
import { flashdetail } from '../../api/flash/index.js';
import { cloudStoreInfo } from '../../api/merchant/index.js';
import { imageUrl } from '../../utils/tools.js';
export default {
	data() {
		return {
			store_id: null,
			store_info: {},
			tokenValue: ''
		};
	},
	async onLoad(option) {
		this.tokenValue = await uni.getStorageSync('token');
		if (this.tokenValue) {
			const { store_id } = option;
			if (store_id) {
				this.store_id = store_id;
			} else {
				const scene = option.scene;
				const sceneInfo = decodeURIComponent(scene);
				this.store_id = sceneInfo.split('=')[1];
			}
			this.getcloudStoreInfo();
		} else {
			uni.showToast({
				title: '未登录',
				icon: 'none',
				duration: 1500
			});
			setTimeout(() => {
				uni.reLaunch({
					url: '/pages/loginMain/loginMain'
				});
			}, 1500);
		}
	},

	computed: {
		bottomStyle() {
			const systemInfo = uni.getSystemInfoSync();
			const { safeAreaInsets } = systemInfo;
			const bottomSafeAreaHeight = safeAreaInsets.bottom || 0;
			return `padding-bottom: ${bottomSafeAreaHeight ? bottomSafeAreaHeight + 'px' : '20rpx'}`;
		}
	},
	methods: {
		// 点击申请
		async getclerkApplication() {
			try {
				const resData = await userStaffApply({
					store_id: this.store_id
				});
				if (resData.code == 1) {
					uni.showToast({
						title: resData.msg,
						icon: 'none',
						duration: 1000
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/nationwideDelivery/nationwideDelivery'
						});
					}, 1500);
				}
			} catch (e) {
				throw Error(e);
			}
		},

		// 获取门店信息
		async getcloudStoreInfo() {
			try {
				const resData = await flashdetail({
					id: this.store_id
				});
				this.store_info = resData.data;
			} catch (e) {
				throw Error(e);
			}
		},

		imageUrls(url) {
			return imageUrl(url);
		}
	}
};
</script>

<style scoped lang="scss">
.clerkApplication {
	.store_info_image {
		text-align: center;
		padding-top: 50px;
	}
	.store_info_name {
		text-align: center;
		margin-top: 20px;
		font-size: 14px;
	}
}
.bankCard-btn {
	box-sizing: border-box;
	padding: 20rpx;
	padding-bottom: 0px;
	background-color: #fff;
	position: fixed;
	bottom: 0px;
	left: 0px;
	width: 100%;
	.btn {
		background-color: #e43927;
		color: #fff;
		height: 80rpx;
		border-radius: 8px;
		line-height: 80rpx;
		text-align: center;
	}
}
</style>
